//====================================================================================================
//	File Name		:	functions.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Javascript Utility functions
//	Author			:	Nirmal Patel
//	Creation Date	:	11-Nov-2003
//	Copyright		:	Copyrights © 2003 Dot Infosys
//	Email			:	info@dotinfosys.com
//	History			:
//						Date						Author						Remark
//						11-Nov-2003					Nirmal Patel				Initial Release
//
//====================================================================================================
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
var ns6=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1;
var ns4=document.layers;

/////for right click disabled
/*
var message="Sorry, you can not right click on this page. \nImage copy is prohibited by law."; 
// Don't edit below!
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
*/

//====================================================================================================
//	Function Name	:	popupWindowURL
//	Purpose			:	Whenever you wanna open a link into a new window just call this function
//								you need to pass some arguemnts as described below.
//	Parameters		:	
//								url  = url to be open in the new window
//								winname = winname is the window name for the reference of that window
//								w is the width
//								h is the height
//								menu is the parameter, if you want menubar to be enabled on the window
//								resize if you wanna resize the window
//								scroll i fyou needed
//								x and y are the co-ordinates where you wld like to show the window on the screen
//	Return			:	true or false
//	Author			:	Nirmal Patel
//	Creation Date	:	11-Nov-2003
//----------------------------------------------------------------------------------------------------

function popupWindowURL(url, winname,  w, h, menu, resize, scroll, x, y) {
	
	//alert('here');
	if (winname == null) winname = "newWindow";
	if (w == null) w = 600;
	if (h == null) h = 600;
	if (resize == null) resize = 1;
	
	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scroll) scrolltype = "scrollbars";
	
	if (x == null || y == null) {
		cwin=window.open(url,winname,"" + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h + ",statusbars=no");
	}
	else {
		cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," +  menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h + ",statusbars=no");
	}
	if (!cwin.opener) cwin.opener=self;
		cwin.focus();
	
	return true;
}

/////change statelist function by selecting country

function change_state_list(frm,lstcountry,stateSel,state_combo_name)
{
	cat = lstcountry.options[lstcountry.selectedIndex].value;
	with(frm)
	{
		for(i=0; i<arrState.length; i++)
		{
			if(arrState[i][0] == cat)	break;
		}
	
		if(i!=arrState.length)
		{
			state_combo_name.disabled=false;
			state_combo_name.length = 1;
			for(j=1; j<arrState[i].length; j+=3)
			{
				state_combo_name.length++;
				state_combo_name[state_combo_name.length-1].value = arrState[i][j];
				state_combo_name[state_combo_name.length-1].text = arrState[i][j+1];
				if(stateSel == arrState[i][j])
				{
					state_combo_name[state_combo_name.length-1].selected = true;
				}
			}
	
		}
		else
		{
			state_combo_name.length = 1;
			state_combo_name.disabled=true;
		}
		
	}
}

function change_city_list(lststate)
{
	
	with(document.frmRegistration1)
	{
		cat = lststate.options[lststate.selectedIndex].value;
		submit();
	}
}
	

///////////////mouseuverStyle function
function getFocus(id, flg, mouseuverStyle, originalStyle)
{
	if(flg)
		id.className = mouseuverStyle;
	else
		id.className = originalStyle;
}


///for your popup
function returntohome(filename)
{
	window.parent.opener.location='../'+filename;
	window.parent.opener.focus(); 
	window.close();
}

//====================================================================================================
//	Function Name	:	Form_Submit()
//	Purpose			:	This function will executed when user submits a form. It checks validity of
//						every field in the form.
//
//	Parameters		:	frm  - form name
//	Return			:	true or false
//	Author			:	Manoj Rana
//	Creation Date	:	07-June-2003
//----------------------------------------------------------------------------------------------------
function CheckBox_Click(validationType, ctlName, eventCaller)
{
	/*
	switch(validationType)
	{
		case '1STORANY':
			if(eventCaller.value == 1)
			{
				for(i=1;i<document.all(ctlName).length;i++)
					document.all(ctlName)[i].checked = false;
			}
			else
			{
				document.all(ctlName)[0].checked = false;
			}
			break;
	}*/
	return true;
}


function ComboBox_Change(frm, fld)
{
	with(frm)
	{
		if(fld.name == 'country_id')
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&' + fld.name + '=' + fld.value+'&flag=1');
			state_id.length = 1;
			state_id[state_id.length-1].text = '---- Loading Data -----';
		}
		else if(fld.name == 'state_id')
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&' + fld.name + '=' + fld.value+'&flag=1');
			city_id.length = 1;
			city_id[city_id.length-1].text = '---- Loading Data -----';
		}
		else
		{
			// Do nothing
		}
	}
}

/* location change functions*/
function Country_Change(frm,stateSel)
{
	with(frm)
	{
		window.frames['dataframe'].window.location.replace( Site_URL + 'location.php?action=loader&country_id=' + frm.country_id.value + '&stateSel='+stateSel ); 
		state_id.length = 1;
		state_id[state_id.length-1].text = '---- Loading Data -----';
	}
}

function Fill_State_Data(arrState,stateSel)
{
	with(document.all)
	{
		if(arrState.length > 0)
		{
			state_id.length 			= 1;
			state_id.disabled			= false;
			state_id.style.display 		= "block";
			text_state_id.style.display = "none";
			
			//city_id.disabled			= true;
			//city_id.length 				= 1;
			//city_id[city_id.length-1].text = '---- Select City -----';
			//city_id.style.display 		= "block";
			//text_city_id.style.display 	= "none";
			city_id.style.display 	= "none";
			text_city_id.style.display 	= "block";
			
			
			for(i=0; i < arrState.length; i++)
			{
				state_id.length++;
				state_id[state_id.length-1].value 	= arrState[i][0];
				state_id[state_id.length-1].text 	= arrState[i][1];
				
				///for default state selection
				if(stateSel == arrState[i][0])
				{
					state_id[state_id.length-1].selected = true;
				}
			}

			state_id[0].text = '----- Select State -----';
		}
		else
		{
			state_id.disabled			= true;
			city_id.disabled			= true;
			state_id.style.display 		= "none";
			text_state_id.style.display = "block";
			city_id.style.display 		= "none";
			text_city_id.style.display 	= "block";
		}
	}
	
}

function State_Change(frm,citySel)
{
	with(frm)
	{
			window.frames['dataframe'].window.location.replace( Site_URL + 'location.php?action=loader&country_id=' + frm.country_id.value + '&state_id=' + frm.state_id.value + '&citySel='+citySel ); 
			//city_id.length = 1;
			//city_id[city_id.length-1].text = '---- Loading Data -----';
			
			//text_city_id.text = '';
			
	}
}

function Fill_City_Data(arrCity,citySel)
{
	with(document.all)
	{
		//alert(arrCity.length);
		if(arrCity.length > 0)
		{
			city_id.disabled=false;
			city_id.length 				= 1;
			city_id.style.display 		= "block";
			text_city_id.style.display 	= "none";
		
			for(i=0; i < arrCity.length; i++)
			{
				city_id.length++;
				city_id[city_id.length-1].value = arrCity[i][0];
				city_id[city_id.length-1].text = arrCity[i][1];
				
				///for default state selection
				if(citySel == arrCity[i][0])
				{
					city_id[city_id.length-1].selected = true;
				}
			}
			city_id[0].text = '----- Select City -----';
		}
		else
		{
			//city_id.disabled=true;
			city_id.style.display 	= "none";
			text_city_id.style.display 	= "block";
		}
	}
}

function Get_City_Combo(citySel,frm)
{
	with(document.all)
	{
		if(state_id.disabled==false)
		{
			State_Change(frm,citySel);//state change	
			clearInterval(timer)
		}
	}
}
//////



// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;

// Duration of crossfade (seconds)
var crossFadeDuration = 3;

// Specify the image files
var Pic = new Array();
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'right_img1.jpg'
Pic[1] = 'right_img4.jpg'
Pic[2] = 'right_img3.jpg'
Pic[3] = 'right_img2.jpg'
Pic[4] = 'right_img5.jpg'

// do not edit anything below this line
var t;
var imgCnt = 0;
var imgTotal = Pic.length;
var preLoad = new Array();

for (i = 0; i < imgTotal; i++) {
	preLoad[i] = new Image();
	preLoad[i].src = './templates/images/' + Pic[i];
}

function runSlideShow() {

	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=5)";
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();

	}
	document.images.SlideShow.src = preLoad[imgCnt].src;
//	alert();
	
	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}

	imgCnt = imgCnt + 2;
	if (imgCnt > (imgTotal - 1)) imgCnt = imgCnt - imgTotal;

	t = setTimeout('runSlideShow()', slideShowSpeed);
}


////// navigation panel functions
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flvFSTI3(v1,v2){//v1.01
var v3;if (v1.filters[0]&&v1.filters[0].status==2){v1.filters[0].Stop();}if (v2==0){v3="blendTrans(Duration="+v1.STI8+")";}else {v3="revealTrans(Duration="+v1.STI8+",Transition="+(v2-1)+")";}v1.style.filter=v3;}

function flvFSTI1(){//v1.01
// Copyright 2003, Marja Ribbers-de Vroed, FlevOOware (www.STI1.nl/dreamweaver/)
var v1=arguments,v2=document,v3;v2.STI4=new Array();v2.STI7=(navigator.userAgent.toLowerCase().indexOf("mac")!=-1);for (var v4=0;v4<v1.length-2;v4+=5){v3=MM_findObj(v1[v4]);if (v3){v3.STI5=v3.src;v3.STI6=v1[v4+1];v3.STI2=v1[v4+2];v3.STI3=v1[v4+3];v3.STI8=v1[v4+4];v2.STI4[v2.STI4.length]=v3;if (v3.filters&&!v2.STI7){flvFSTI3(v3,v3.STI2);v3.onfilterchange=flvFSTI4;v3.filters[0].Apply();}v3.src=v3.STI6;if (v3.filters&&!v2.STI7){v3.filters[0].Play();}}}}

function flvFSTI2(){//v1.01
var v1,v2=document,v3=v2.STI4,v4;for (v4=0;v3&&v4<v3.length&&(v1=v3[v4])&&v1.STI5;v4++){if (v1.filters&&!v2.STI7){flvFSTI3(v1,v1.STI3);v1.filters[0].Apply();}v1.src=v1.STI5;if (v1.filters&&!v2.STI7){v1.filters[0].Play();}}}

function flvFSTI4(){//v1.01
this.style.filter="";}

function KW_s(r, g, b, el) {
    d=document;hr=r.toString(16);hg=g.toString(16);hb=b.toString(16);
	hr=(hr.length==1)?"0"+hr:hr;hg=(hg.length==1)?"0"+hg:hg;hb=(hb.length==1)?"0"+hb:hb;
	if (d.getElementById) d.getElementById(el).style.color="#"+hr+hg+hb;
}

function KW_c(a,b,s,i) { return Math.floor(a*((s-i)/s)+b*(i/s)) }

function KW_fade(r,g,b,e,n,l,s,o){
    for(i=0;i<=s;i++)setTimeout("KW_s("+KW_c(r,e,s,i)+","+KW_c(g,n,s,i)+","+KW_c(b,l,s,i)+",'"+o+"');",i*s);
}
//-->


