function Validate_Blank(obj,msg)
{
		if(obj.value=='')
		{	
			obj.focus();			
			alert(msg);
			return false;
		}
}
function checkCombo(cmbObject,defaultValue,msgDisplay)
{
var strData;
strData=cmbObject.value;
if(strData == defaultValue)
{
	alert("Please Select Appropriate Option from the  Following Field : " + msgDisplay);
	cmbObject.focus();
	return false;
}
}
function selectAllCB(objChk,strFormName,strMainId) {

	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "checkbox") {

			if(ele[i].id==strMainId) {

				ele[i].checked=objChk.checked;

			}

		}

	}

}



// cross platform equiv. to document.getElementById

function gGetElementById(s) {

  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);

  return o == null ? false : o;

}



function getCheckBoxSelectCount(strFormName,strMainId) {



	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	var cnt=0;

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "checkbox") {

			if(ele[i].id==strMainId) {

				if(ele[i].checked) {

					cnt=cnt+1;
				}

			}

		}

	}

	return(cnt);

}



function getCheckBoxSelectedValues(strFormName,strMainId) {

	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	var cnt=0;

	var ans="";

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "checkbox") {

			if(ele[i].id==strMainId) {

				if(ele[i].checked) {

					if(ans=="") 

						ans=ele[i].value;

					else

						ans=ans + "," + ele[i].value;

				}

			}

		}

	}



	return(ans);

}



function actions(strFormName,strAction,strMainId,objCmb) {

	var ans;

	var actionText;

	var frm= gGetElementById(strFormName);

	var cmbAction;

	var cnt;

	if(objCmb.value!="0" && objCmb.value!="-") {

		ans=getCheckBoxSelectedValues(strFormName,strMainId);

		if(ans != "") {

			var objIds;

			objIds=gGetElementById(strMainId + "s");

			if(objCmb.value.indexOf("*S") > 0){

				cnt=getCheckBoxSelectCount(strFormName,strMainId);

				if(cnt==1) {

					objIds.value=ans;

					frm.submit();

				} else {

					alert("Please Select Single Record.");

					objCmb.value=0;

					return false;

				}

			} else if(objCmb.value.indexOf("*M") > 0){

				objIds.value=ans;

				frm.submit();

			} else {

				actionText=gGetElementById(strAction).options[gGetElementById(strAction).selectedIndex].text;

				if(confirm("Are you sure to perform " + actionText + " Action on selected records ?")) {

					objIds.value=ans;

					frm.submit();

				} else {

					objCmb.value=0;

					return false;

				}

			}

		} else {

			alert("You need to some records.");

			objCmb.value=0;

			return false;

		}

	} else {

		objCmb.value=0;

		return false;

	}

}



function resetAndSubmit(strFormName) {

	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "hidden" || ele[i].type == "text") {

			ele[i].value="";

		} else if(ele[i].type == "select-one") {

			ele[i].options[0].selected=true;

		} else {

			

		}

	}

 	return true;

}



function getFront(mainStr,searchStr){

	foundOffset = mainStr.indexOf(searchStr)

	if (foundOffset == -1) {

		return null

	}

	return mainStr.substring(0,foundOffset)

}



// extract back end of string after searchString

function getEnd(mainStr,searchStr) {

	foundOffset = mainStr.indexOf(searchStr)

	if (foundOffset == -1) {

		return null

	}

	return mainStr.substring(foundOffset+searchStr.length,mainStr.length)

}



// insert insertString immediately before searchString

function insertString(mainStr,searchStr,insertStr) {

	var front = getFront(mainStr,searchStr)

	var end = getEnd(mainStr,searchStr)

	if (front != null && end != null) {

		return front + insertStr + searchStr + end

	}

	return null

}



// remove deleteString

function deleteString(mainStr,deleteStr) {

	return replaceString(mainStr,deleteStr,"")

}



// replace searchString with replaceString

function replaceString(mainStr,searchStr,replaceStr) {

	var front = getFront(mainStr,searchStr)

	var end = getEnd(mainStr,searchStr)

	if (front != null && end != null) {

		return front + replaceStr + end

	}

	return null

}

function edCmdImage(strCommand,opType) {

//opType=1 = Enable

//opType=2 = Disable

	var Img;

	var temp;

	var strReplace;

	var strReplaceBy;

	Img=gGetElementById("cmd"+strCommand);

	temp=Img.src;

	

	if(getFront(temp,strCommand + "_o.jpg")) {

		strReplace=strCommand + "_o.jpg";

	} else {

		strReplace=strCommand + "_d.jpg";

	}

	

	if(opType=="1") {

		strReplaceBy=strCommand + "_o.jpg";

	} else {

		strReplaceBy=strCommand + "_d.jpg";

	}

	temp=replaceString(temp,strReplace,strReplaceBy);

	Img.src=temp;

}

function clickCmdImgs(opType,baseURL,strFormName,cbId) {

	var cnt;

	var a;

	switch(opType) {

		case "add":

			a=gGetElementById("addLink"+strFormName);

			window.location=a;

			break;

		case "edit":

			a=gGetElementById("editLink"+strFormName);

			a=a + getCheckBoxSelectedValues(strFormName,cbId);

			cnt=getCheckBoxSelectCount(strFormName,cbId)		

			if(cnt==1) {

				window.location=a;

			}

			break;

		case "delete":

			a=gGetElementById("deleteLink"+strFormName);

			a=a + getCheckBoxSelectedValues(strFormName,cbId);

			cnt=getCheckBoxSelectCount(strFormName,cbId)

			if(cnt>0) {

				window.location=a;

			}

			break;

	}

	return false;

}

function changeCmdImgs(baseURL,strFormName,cbId) {

	var cnt;

	cnt=getCheckBoxSelectCount(strFormName,cbId)

	if(cnt==1) {

		edCmdImage("edit",1);

	} else {

		edCmdImage("edit",0);

	}

	

	if(cnt>0) {

		edCmdImage("delete",1);

	} else {

		edCmdImage("delete",0);

	}

}

function setAddOther(strFieldName) {

		var field;

		field=gGetElementById(strFieldName);

		field.value="1";

		return true;

}

function submitDelete(strFormName,cbId) {

var cnt;

var ids;

cnt=getCheckBoxSelectCount(strFormName,cbId);

if(cnt > 0 ) {

	ids=gGetElementById("deleteIds");

	ids.value=getCheckBoxSelectedValues(strFormName,cbId);

	return true;

} else {

	alert("You need to select the Records to Delete.");

	return false;

}

		

}

function setUrl(){

	var ele;
	var regExp = /\s+/g;	
	var regExp1 = /&+/g;	
	var aString;

	ele=gGetElementById("name");
	ele1=gGetElementById("url");
	
	aString =ele.value;
	
	aString=aString.toLowerCase();
	aString=aString.replace(regExp1,''); 
	aString=aString.replace(regExp,'_'); 
	
	ele1.value=aString;

}
/*
function setUrl(){

	var ele;
	var regExp = /\s+/g;	
	var aString;

	ele=gGetElementById("name");
	ele1=gGetElementById("url");
	
	aString =ele.value;
	
	aString=aString.toLowerCase();
	aString=aString.replace(regExp,'_'); 
	
	ele1.value=aString;

}*/



function getComboValue(){

		var ele;

		ele=gGetElementById("pa");

		ele1=gGetElementById("spa");

		ele2=gGetElementById("province");

		ele3=gGetElementById("city");

		List=Array();

		List['pa']=ele.value;

		List['spa']=ele1.value;

		List['province']=ele2.value;

		List['city']=ele3.value;

		ele5=gGetElementById("list");

		ele5.value=List['pa']+","+List['spa'];

		return true;

}



function search_term(){

		var ele,val;

		ele=gGetElementById("txtTerm");

		if(ele.value=='e.g. toronto; civil lawyer;'){

			ele.value='';

		}

}

function set_same_value(){

	ele=gGetElementById("txtTerm");

	val=ele.value;

	if(val==''){

		ele.value='e.g. toronto; civil lawyer;';

	}

}



function check_combo_exist(){

	ids=Array();

	ids[0]='city_search';

	ids[1]='spa_search';

	ids[2]='city_search_1';

	ids[3]='spa_search_1';
	
	ids[4]='state_search';
	
	ids[5]='city_search2';
	//ids[6]='city_search_adv';
	ids[7]='province_search_adv';

	for(i=0;i<ids.length;i++){

		ele=gGetElementById(ids[i]);

		if(ele){

			Element.hide(ids[i]);

		}

	}

	return true;

}

function registerSelectPA(objChk,ids,idStr) {

	var tempObj;

	if(ids!="") {

		var myIDs=ids.split(",");

		var i=0;

		while (i < myIDs.length) {

			tempObj=gGetElementById(idStr + myIDs[i]);

			tempObj.checked=objChk.checked;

			i+=1;

		}

	}

}
function checkForPresenceInSelect2(optVal, text, selList) {
 for (i = 0; i < selList.length; i++) {
   if (selList.options[i].value == optVal) return true;
   if (selList.options[i].text == text) return true;
 }
 return false;
}
// Logic for moving a multi-select from element1 to element2
function gGetElementById(s) {
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}

function selectAllOptions(oblCmb)
{
var len = oblCmb.length;
for (var i = 0; i < len; ++i) {
 	 oblCmb.options[i].selected = true;
   }
  return;
}

function one2two(element1, element2) {
 var memberList = gGetElementById(element1);
 var selectedList = gGetElementById(element2);
 var len = memberList.length;

 // Ignore any selections that are made to "------"
 for (var i = 0; i < len; ++i) {
   if (memberList.options[i].selected == true) {
	 memberList.options[i].selected = false;
	 if (memberList.options[i].text == "------") {
	   continue;
	 }
	 
	 if (checkForPresenceInSelect2(memberList.options[i].value, memberList.options[i].text, selectedList) == false) {

	   selectedList.options[selectedList.length] = new Option(memberList.options[i].text, memberList.options[i].value);
	   
	 }
   }
 }
}

// moving a multi-select from element2 to element1.
// Actually this assumes that the values being moved are
// already present in element1 and ends up deleting
// the selected values in element2.
function two2one(element1, element2) {
 var selectedList = gGetElementById(element2);
 for (i = selectedList.length -1; i >= 0; i--) {
   if (selectedList.options[i].selected == true) {
	 selectedList.options[i] = null;
   }
 }
}

function one2twoSingle(element1, element2) {
 var memberList = gGetElementById(element1);
 var selectedList = gGetElementById(element2);
 var len = memberList.length;
 for (var i = 0; i < len; i++) {
    if (memberList.options[i].selected == true) {
		memberList.options[i].selected = false;
	 if (checkForPresenceInSelect2(memberList.options[i].value, memberList.options[i].text, selectedList) == false) {
	   selectedList.options[selectedList.length] = new Option(memberList.options[i].text, memberList.options[i].value);
	 }
	}
 }
}

function two2oneSingle(element1, element2) {
	var selectedList = gGetElementById(element2);
	for (i = selectedList.length -1; i >= 0; i--) {
		if(selectedList.options[i].selected==true) {
			selectedList.options[i].selected=false;
			selectedList.options[i] = null;
		}
	}
}

function setTextarea() {
		ele=gGetElementById('editor_Html Text');
		ele1=gGetElementById('editor_Simple Text');
		simed=gGetElementById('simTextEd1');
		htmed=gGetElementById('htmlTextEd1');
		if(ele.checked){	
			simed.style.display='none';
			htmed.style.display='';
			
			/*document.getElementById('simTextEd').style.display='none';
			document.getElementById('htmlTextEd').style.display='';*/
		}
		else if(ele1.checked){
			htmed.style.display='none';			
			simed.style.display='';
		}
}

function SelectList() {
		
	/*	pro=gGetElementById('SelMovie');
		pList=gGetElementById('ProvinceList');
		pList2=gGetElementById('Province');
		*/
		pro1=gGetElementById('SelType');
		pList1=gGetElementById('TypeList');
		pList21=gGetElementById('Type');
			//pro.style.display='none';
			pro1.style.display='none';
}


function DisplayDivs() {
		ele=gGetElementById('BannerType');
		
		cat=gGetElementById('Category');
		cat1=gGetElementById('Category1');
		city=gGetElementById('City');
		pList=gGetElementById('firstListAdd');
		pList2=gGetElementById('firstAdd');
		cList=gGetElementById('firstListCity');
		cList2=gGetElementById('firstCity');
		if(ele.value=='Advertisement'){
			cat.style.display='';
			city.style.display='';
		}
		else {
			
			cat.style.display='none';
			city.style.display='none';
		}
}

function checkStrLen(txtObj,minLength,MaxLength,msgDisplay)
{
var strData;
strData=txtObj.value;
if(strData.length < Number(minLength))
{
	alert("Please Enter Valid Value In The Following Field : " + msgDisplay);
	txtObj.focus();
	return false;
}
if(strData.length > Number(MaxLength))
{
	alert("Please Enter Value Lesser Than " + MaxLength +" In The Following Field : " + msgDisplay);
	txtObj.focus();
	return false;

}
}
function checkEmail(objTxt) {
	var GoodChars = "@_-.:/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var UpperEmail = objTxt.value.toUpperCase()
	var ValidChars = true;
	
	for (tfCharNum = 0; tfCharNum > objTxt.value.length; tfCharNum++) {
		Char = UpperEmail.charAt(tfCharNum);
		for (gcCharNum = 0;  gcCharNum < GoodChars.length;  gcCharNum++) {
				 if (Char == GoodChars.charAt(gcCharNum))
			     break;
		}
				 
		if (gcCharNum == GoodChars.length)   {
		     ValidChars = false;
		     break;
   		}
	}
	
	if (!ValidChars || objTxt.value.length < 7 || 
		objTxt.value.indexOf("@") == "-1" ||
		objTxt.value.indexOf(".") == "-1" || 
		//objTxt.value.indexOf("..") != "-1" || 
		objTxt.value.indexOf("@.") != "-1" || 
		objTxt.value.indexOf("@:") != "-1" || 
		objTxt.value.indexOf("@/") != "-1" || 
		objTxt.value.indexOf("@-") != "-1" || 
		objTxt.value.indexOf("@_") != "-1" || 
		objTxt.value.indexOf(".@") != "-1" || 
		objTxt.value.indexOf(":@") != "-1" || 
		objTxt.value.indexOf("/@") != "-1" || 
		objTxt.value.indexOf("-@") != "-1" || 
		objTxt.value.indexOf("_@") != "-1" || 
		objTxt.value.indexOf("@") != objTxt.value.lastIndexOf("@")) {
		objTxt.focus();
			return (false);
	}
	return (true);
}
function validate_frm(){
	var email;
	email=gGetElementById("femail");
	if(!checkEmail(email)){
		email.focus();
		alert("Please Enter Proper Value For Email");
		return false;
	}
return;
}
function checkPwds(){
	var password;
	var confirm_password;
password=gGetElementById("password");
confirm_password=gGetElementById("confirm_password");
if(password.value!='' && confirm_password.value!=''){
	if(confirm_password.value!=password.value){
			alert("Passwords do not match");
			password.value='';
			confirm_password.value='';
			password.focus();
			return false;
	}
}
	
return;	
}

function setMe(val,ele){
	var olddiv = document.getElementById(ele);
	if(val=='pre'){
		olddiv.value=1;
	}else{
		olddiv.value=2;
	}
	return;
}
function chk_selection(){
	var title=document.getElementById("title_val");
	var rate=document.getElementById("rate");
	if(Validate_Blank(title,"Please Enter Subject") == false)
	{return false;}
	if(checkCombo(rate,0,"Rate") == false){
	return false; }
	
	return true;
}

function validate_Contactus_Data()
{
	var name=document.getElementById("name");
	
	var email=document.getElementById("valid_email");	
	var comments=document.getElementById("comment");
	
	if(Validate_Blank(name,"Please Enter Name") == false)
	{return false;}
	if(Validate_Blank(email,"Please Enter Email Id") == false)
	{return false;}
	if(checkEmail(email)==false){
		alert("Enter Valid Email Address");
		return false;
	}
	if(Validate_Blank(comments,"Please Enter comments") == false)
	{return false;}
	
}
function paging_data(url){
	var paging=document.getElementById("paging");	
	window.location=url+"?page="+paging.value;
}
function SelectList() {
		ele=gGetElementById('radio_Channel');
		ele1=gGetElementById('radio_Movie');
		ele2=gGetElementById('radio_All Movies');
		ele3=gGetElementById('radio_Package');
		ele4=gGetElementById('radio_All Packages');
		ele5=gGetElementById('radio_Everything');
		
		cat=gGetElementById('Channel');
		pro=gGetElementById('Movie');
		pack=gGetElementById('Package');
		pList=gGetElementById('firstListMovie');
		pList2=gGetElementById('firstMovie');
		cList=gGetElementById('firstListChannel');
		cList2=gGetElementById('firstChannel');
		pcList=gGetElementById('firstListPackage');
		pcList2=gGetElementById('firstPackage');
		
		if(ele1.checked){
			cat.style.display='none';
			pack.style.display='none';
			pro.style.display='';
			pList='';
			selectAllOptions(cList2);
			two2one('firstListChannel', 'firstChannel');
		}else if(ele.checked){
			cList='';
			selectAllOptions(pList2);
			two2one('firstListMovie', 'firstMovie');
			cat.style.display='';
			pack.style.display='none';
			pro.style.display='none';
		}else if(ele3.checked){
			pcList='';
			selectAllOptions(pList2);
			two2one('firstListMovie', 'firstMovie');
			pack.style.display='';
			cat.style.display='none';
			pro.style.display='none';
		}else{
			cat.style.display='none';
			pro.style.display='none';
			pack.style.display='none';
		}
}
