// JavaScript Document

function checksearch()

{

	var frmObj = document.searchform;

	if(isEmpty(Trim(frmObj.country.value)))

	{

		alert('Member should not be blank.');

		frmObj.country.focus();

		return false;

	}	

}

function validateLogin()

{

	var frmObj = document.login;

	if(isEmpty(Trim(frmObj.actname.value)))

	{

		alert('Account Name should not be blank.');

		frmObj.actname.focus();

		return false;

	}

	if(isEmpty(Trim(frmObj.pass.value)))

	{

		alert('Password should not be blank.');

		frmObj.pass.focus();

		return false;

	}

	

	return true;

}



function validateRegister()

{

	var frmObj = document.register;

	

	if(isEmpty(Trim(frmObj.username.value)))

	{

		alert('Username should not be blank.');

		frmObj.username.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.rpassword.value)))

	{

		alert('Password should not be blank.');

		frmObj.rpassword.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.crpassword.value)))

	{

		alert('Confirm Password should not be blank.');

		frmObj.crpassword.focus();

		return false;

	}

	

	if(Trim(frmObj.rpassword.value) != Trim(frmObj.crpassword.value))

	{

		alert('Password and Confirm Password should match.');

		frmObj.crpassword.value = "";

		frmObj.crpassword.focus();

		return false;

	}

	

	if(frmObj.state.selectedIndex <= 0)

	{

		alert('Please select State.');

		frmObj.state.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.contact_person.value)))

	{

		alert('Contact Person should not be blank.');

		frmObj.contact_person.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.description.value)))

	{

		alert('Organisation Name should not be blank.');

		frmObj.description.focus();

		return false;

	}

	

	// *** robertv - 04/03/2010 - job 12658 ***

	if(isEmpty(Trim(frmObj.country_code.value)))

	{

		alert('Mobile country code should not be blank.');

		frmObj.country_code.focus();

		return false;

	}

	// *** end robertv - 04/03/2010 - job 12658 ***

	

	if(isEmpty(Trim(frmObj.mobile.value)))

	{

		alert('Mobile should not be blank.');

		frmObj.mobile.focus();

		return false;

	}

	

	if( !isEmpty(frmObj.email.value) )

    {

        if( !isEmail(frmObj.email.value) )

        {

	        alert("Invalid Email.");

	        frmObj.email.focus();

	        return false;

        }

    }

    else

    {

        alert("Email should not be blank.");

	    frmObj.email.focus();

	    return false;

    }

	

	if(frmObj.payment_method.selectedIndex <= 0)

	{

		alert('Please select Payment Method.');

		frmObj.payment_method.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.details.value)))

	{

		alert('Details should not be blank.');

		frmObj.details.focus();

		return false;

	}
	if(isEmpty(Trim(frmObj.security_code.value)))

	{

		alert('Security field should not be blank.');

		frmObj.security_code.focus();

		return false;

	}

	if(Trim(frmObj.security_code.value)!=Trim(frmObj.hiddedcaptcha.value))

		{

			alert('Security code is invalid');

			frmObj.security_code.focus();

			return false;

		}

	return true;

}





function validateEditInfo()

{

	var frmObj = document.register;

	

	if(isEmpty(Trim(frmObj.description.value)))

	{

		alert('Organisation Name should not be blank.');

		frmObj.description.focus();

		return false;

	}

	

	if(frmObj.state.selectedIndex <= 0)

	{

		alert('Please select State.');

		frmObj.state.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.contact_person.value)))

	{

		alert('Contact Person should not be blank.');

		frmObj.contact_person.focus();

		return false;

	}

		

	if(isEmpty(Trim(frmObj.mobile.value)))

	{

		alert('Mobile should not be blank.');

		frmObj.mobile.focus();

		return false;

	}

	

	if( !isEmpty(frmObj.email.value) )

    {

        if( !isEmail(frmObj.email.value) )

        {

	        alert("Invalid Email.");

	        frmObj.email.focus();

	        return false;

        }

    }

    else

    {

        alert("Email should not be blank.");

	    frmObj.email.focus();

	    return false;

    }

	

	if(frmObj.payment_method.selectedIndex <= 0)

	{

		alert('Please select Payment Method.');

		frmObj.payment_method.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.details.value)))

	{

		alert('Details should not be blank.');

		frmObj.details.focus();

		return false;

	}
	
	

	

	return true;

}



function validatepaymententry()

{

	var frmObj = document.paymententry;

	

	if(isEmpty(Trim(frmObj.country.value)))

	{

		alert('Please enter username');

		frmObj.country.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.country_ID.value)))

	{

		alert('Please enter valid username');

		frmObj.country.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.amount.value)))

	{

		alert('Amount should not be blank.');

		frmObj.amount.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.credit.value)))

	{

		alert('Credit amount should not be blank.');

		frmObj.credit.focus();

		return false;

	}

	if(frmObj.payment.value=='Cheque')

	{

		if(isEmpty(Trim(frmObj.chequeno.value)))

		{

			alert('Cheque no should not be blank.');

			frmObj.chequeno.focus();

			return false;

		}

		if(isEmpty(Trim(frmObj.c_date.value)))

		{

			alert('Cheque date should not be blank.');

			frmObj.c_date.focus();

			return false;

		}

		if(isEmpty(Trim(frmObj.bankname.value)))

		{

			alert('Bank name should not be blank.');

			frmObj.bankname.focus();

			return false;

		}
		
		

	}

}



function validateForgotPass()

{

	var frmObj = document.forgotpass;

	

	if( !isEmpty(frmObj.email.value) )

    {

        if( !isEmail(frmObj.email.value) )

        {

	        alert("Invalid Email.");

	        frmObj.email.focus();

	        return false;

        }

    }

    else

    {

        alert("Email should not be blank.");

	    frmObj.email.focus();

	    return false;

    }

	return true;

}



function validateContact()

{

	var frmObj = document.addcontact;

	

	if(frmObj.bulk_sms_contact_type.selectedIndex <= 0)

	{

		alert('Please select Group.');

		frmObj.bulk_sms_contact_type.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.fname.value)))

	{

		alert('FirstName should not be blank.');

		frmObj.fname.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.lname.value)))

	{

		alert('LastName should not be blank.');

		frmObj.lname.focus();

		return false;

	}

	

	if(frmObj.state.selectedIndex <= 0)

	{

		alert('Please select a Country.');

		frmObj.state.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.mobno.value)))

	{

		alert('Mobile Number should not be blank.');

		frmObj.mobno.focus();

		return false;

	}

	

	return true;

}





function validateCPass()

{

	var frmObj = document.changepass;

	

	if(isEmpty(Trim(frmObj.oldpass.value)))

	{

		alert('Old Password should not be blank.');

		frmObj.oldpass.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.newpass.value)))

	{

		alert('New Password should not be blank.');

		frmObj.newpass.focus();

		return false;

	}

	

	if(isEmpty(Trim(frmObj.confpass.value)))

	{

		alert('Confirm Password should not be blank.');

		frmObj.confpass.focus();

		return false;

	}

	

	if(Trim(frmObj.newpass.value) != Trim(frmObj.confpass.value))

	{

		alert('Password and Confirm Password should match.');

		frmObj.confpass.value = "";

		frmObj.confpass.focus();

		return false;

	}

	

	return true;

}



function validateGName()

{

	var frmObj = document.addgroup;

	

	if(isEmpty(Trim(frmObj.groupname.value)))

	{

		alert('GroupName should not be blank.');

		frmObj.groupname.focus();

		return false;

	}

	

	return true;

}



function validateGNews()

{

	var frmObj = document.addnew;

	var title = frmObj.newstitle.value;

	

	if(isEmpty(Trim(frmObj.newstitle.value)))

	{

		alert('News Title should not be blank.');

		frmObj.newstitle.focus();

		return false;

	}

	else if (parseInt(title.length) > 100)

	{

		alert('News Title should not be greter than 100 characters.');

		frmObj.newstitle.focus();

		return false;

	}

	

		/*if(isEmpty(Trim(frmObj.newsdesp.value)))

	{

		alert('News Description should not be blank.');

		frmObj.newsdesp.focus();

		return false;

	}
*/

	

	return true;

}



function validateGAdverts()

{

	var frmObj = document.addnew;

	

	if(isEmpty(Trim(frmObj.advertname.value)))

	{

		alert('Advert Name should not be blank.');

		frmObj.advertname.focus();

		return false;

	}	

	

	if(isEmpty(Trim(frmObj.url.value)))

	{

		alert('Advert Url should not be blank.');

		frmObj.url.focus();

		return false;

	}

		

	if(isEmpty(Trim(frmObj.alttext.value)))

	{

		alert('Advert Text should not be blank.');

		frmObj.alttext.focus();

		return false;

	}

	

	return true;

}



function validateCredits()

{

	var frmObj = document.addgroup;

	

	if(isEmpty(Trim(frmObj.credit.value)))

	{

		alert('User Credit should not be blank.');

		frmObj.credit.value == 0;

		frmObj.credit.focus();

		return false;

	}

	

	return true;

}





function toggle(id)

{

	el = document.getElementById(id);

	var display = el.style.display ? '' : 'none';

	el.style.display = display;

}



function confirmGroupDelete(groupName)

{

	return confirm("Do you want to delete Group " + groupName+ "?");

}



function confirmContactDelete(contactName)

{

	return confirm("Do you want to delete Contact " + contactName + "?");

}



function checkFields()

{

	if(document.forms["create_message_form"].message.value == "")

	{

		alert("Please enter the SMS message you would like to send.");

		return false;

	}

	else if (document.forms["create_message_form"].termsCheck.checked == false)

	{

		alert("Please confirm that you accept the terms and conditions.");

		return false;

	}

	return true;

}



function clearMessage()

{

	document.forms["create_message_form"].message.value = "";

}



function loadMessage(inText)

{

	document.forms["create_message_form"].message.value = inText;

}





function saveMessage()

{

    // *** robertv - 05/03/2010 - job 12661 ***

	var thisForm = document.forms["create_message_form"];

	thisForm.action = "/index.php?page=e105bb228261db6847c5e19db449dc4f";

	thisForm.save_message.value = 1;

	if(thisForm.message.value == "")

		alert("Please enter a message to save in the message field.");

	else

		thisForm.submit();

	// *** end robertv - 05/03/2010 - job 12661 ***

}



function storeCaret (textEl)

{

	if (textEl.createTextRange) 

		textEl.caretPos = document.selection.createRange().duplicate();

}

/*

function insertAtCaret (textEl, text)

{

	if (textEl.createTextRange && textEl.caretPos)

	// IE

	{

		var caretPos = textEl.caretPos;

		caretPos.text =

		caretPos.text.charAt(caretPos.text.length - 1) == " " ?

		text + " " : text;

		textEl.focus();

	}

	else if (textEl.selectionEnd)

	// FF and NN

	{

		var caretPos = textEl.selectionEnd;

		textEl.value = textEl.value.substring(0,caretPos) + text + textEl.value.substring(caretPos, textEl.value.length);



		var newCaretPos = caretPos + text.length;

		textEl.setSelectionRange(newCaretPos, newCaretPos);

		textEl.focus();

	}

	else

		textEl.value  = text;

}

*/

function insertAtCaret(obj, string)

{

obj.focus();



if (typeof(document.selection) != 'undefined')

{

var range = document.selection.createRange();



if (range.parentElement() != obj)

return;



range.text = string;

range.select();

}

else if (typeof(obj.selectionStart) != 'undefined')

{

var start = obj.selectionStart;



obj.value = obj.value.substr(0, start)

+ string

+ obj.value.substr(obj.selectionEnd, obj.value.length);



start += string.length;

obj.setSelectionRange(start, start);

}

else

obj.value += string;



obj.focus();

}



function checkUncheckAll(el)

{

	var inputFields = document.getElementsByTagName("input");

	for(var i=0; thisInput=inputFields[i]; i++)

	{

		if (thisInput.type == "checkbox")

			thisInput.checked = el.checked;

	}

	//document.getElementById('3').checked=0;

	return false;

}



function checkUncheckone(el)

{

	var c = document.getElementById("cc").value;

	if(c==1){

	document.getElementById(el).checked=1;

	document.getElementById("cc").value=0;

	}else{

		document.getElementById(el).checked=0;

		document.getElementById("cc").value=1;

	}

	return false;

}

function checkUncheckother(el,val)

{

	var inputFields = document.getElementsByTagName("input");

	for(var i=0; thisInput=inputFields[i]; i++)

	{

		if (thisInput.type == "checkbox")

			thisInput.checked = el.checked;

	}

	document.getElementById(val).checked=0;

	document.getElementById('call').checked=0;

	document.getElementById('cone').checked=0;

	return false;

}



// *** robertv - 05/03/2010 - job 12660 ***

function checkGroup(el, val){

    var row = document.getElementById("row"+val);

    var inputFields = row.getElementsByTagName("input");

    for(var i=0; thisInput=inputFields[i]; i++) {

        if (thisInput.type == "checkbox")

			thisInput.checked = el.checked;

    }

    row.style.display = "";

}

// *** end robertv - 05/03/2010 - job 12660 ***



function somethingIsChecked()

{

	var inputs = document.getElementsByTagName("input");

	for(var i=0; thisInput = inputs[i]; i++)

		if (thisInput.type == "checkbox" && thisInput.checked && thisInput.name != "checkAll")

			return true;



	alert("Please check at least one contact to send an SMS to.");

	return false;

}



function confirmUserDelete(userName)

{

	return confirm("Do you want to delete User " + userName + "?");

}



function addCredit(Obj,username,oldcredit)

{

	if(Obj.value != "")

		document.getElementById('totaldiv').innerHTML = "Total Credit for " + username + " would be " + eval(eval(oldcredit) + eval(Obj.value));

}



function removeCredit(Obj,username,oldcredit)

{

	if(Obj.value != "")

		document.getElementById('totaldiv').innerHTML = "Total Credit for " + username + " would be " + eval(eval(oldcredit) - eval(Obj.value));

}



function confirmNewDelete()

{

	return confirm("Do you want to delete News?");

}



function confirmAdvertDelete()

{

	return confirm("Do you want to delete Advert?");

}



// Validation for email duplication



var xmlHttp		

function validateThis(str)

{	 

	

	xmlHttp=GetXmlHttpObject()

	if (xmlHttp==null)

	{

		alert ("Browser does not support HTTP Request")

		return

	}

	var url="checkemail.php"  

	url=url+"?q="+str

	xmlHttp.onreadystatechange=stateChanged 

	xmlHttp.open("GET",url,true)

	xmlHttp.send(null)

}

function stateChanged() 

{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

	{ 

		var e = xmlHttp.responseText ;

		if(e=='Success')

		{

		}

		else

		{

			document.getElementById('tb1').innerHTML = e ;

			document.register.contact_person.value='';

		}

	}  

} 

function GetXmlHttpObject()

{

	var xmlHttp=null;

	try

 	{

  		xmlHttp=new XMLHttpRequest();

 	}

	catch (e)

 	{

 		try

  	{

  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

function checkdisable(str)

{

	if(str=='')

	{

		document.frmcronwork.days_after.disabled=false;

	}else{

		document.frmcronwork.days_after.disabled=true;

	}

}



// popup a URL

function popUpNoMenu (url, width, height, left, top) 

{

	day = new Date();

	id = day.getTime();

	if (width == null) width = 800;

	if (height == null) height = 600;

	if (left == null) left = 80;

	if (top == null) top = 80;

	eval("page" + id + " = window.open('" + url + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "');");

}
