var emptyString = " field is blank. Please enter a ";
var emptyCombo = " field is blank. Please select a ";

function logout(){
	if (confirm('Are you sure you want to logout?')){
		document.form1.userAction.value = "logout";
		return true;
	}
	return false;
}

function EditInfo(objId){
	document.location.href="editInfo.asp?userId=" + objId;
}

function searchValidate(){
	var keyword = document.form1.searchKeyword;
	//alert('asdf');
	if ( validateString(keyword, "Keyword")){
		keyword = escape(keyword.value);
		document.location.href = "productSearch.asp?keyword=" + keyword;
	}
	return false;
}

function sendComment(){
	if(validateEmail(document.form1.commentEmail,"Email") && 
	   validateCombo(document.form1.commentType,"Comment Type") && 
		 validateString(document.form1.comment,"Comment")){
		document.form1.userAction.value = "sendComment";
		return true;
	}
	return false;
}

function subscribeConfirmation(){
	
		if (validateEmail(document.form1.newsletterEmail, "Email") ){
				 if (confirm('Are you sure you want to register?')){
				 		document.location.href='index.asp?userAction=subscribe&email='+ document.form1.newsletterEmail.value;
				 }
			}
}

//spawn new window
function NewWindow(mypage, myname, w, h, strStatus, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',status='+strStatus+', scrollbars='+scroll+',no'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function validateDob(myfield, s){
	if (notNull(myfield.value)&& notBlank(myfield.value))
		return true
	else {
		document.form1.dateSelect.focus();
		alert("The " + s + emptyString + s)
		return false
	}
}

function validateSecondPhoneNo(myfield, s){
	if (myfield.value.length == 8){
		return true;
	}else{
		alert("The " + s + " must have 8 digits")
		myfield.focus();
		return false;
	}
}

function validateFirstPhoneNo(myfield, s){
	if (myfield.value.length == 2){
		return true;
	}else{
		alert("The " + s + " must have 2 digits")
		myfield.focus();
		return false;
	}
}

function validateFirstHpNo(myfield, s){
	if (myfield.value.length == 3){
		return true;
	}else{
		alert("The " + s + " must have 3 digits")
		myfield.focus();
		return false;
	}
}

function validateSecondHpNo(myfield, s){
	if (myfield.value.length == 7){
		return true;
	}else{
		alert("The " + s + " must have 7 digits")
		myfield.focus();
		return false;
	}
}

function validatePhoneNo(myfield, s, myfield2, s2){
if (trim(myfield.value)==''){
    alert("The " + s + " is empty.")
    myfield.focus()
    return false
}else{
	if (trim(myfield.value)!=''){
		if (trim(myfield2.value)==''){
			alert("The " + s2 + " is empty.")
			myfield2.focus()
			return false
		}else{
			for (i = 0; i < myfield.value.length; i++){
			// Check that current character is number.
				c = myfield.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s + " is not a valid number.")
					myfield.focus()
					return false;
				}
			}
			for (i = 0; i < myfield2.value.length; i++){
				// Check that current character is number.
				c = myfield2.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s2 + " is not a valid number.")
					myfield2.focus()
					return false;
				}
			}
			if (validateFirstPhoneNo(myfield, "First Phone No") &&
				validateSecondPhoneNo(myfield2 , "Second Phone No" )){
				return true;
			}else{
				return false;
			}
		}
	}else if (trim(myfield2.value)!=''){
		if (trim(myfield.value)==''){
			alert("The " + s + " is empty.")
			myfield.focus()
			return false
		}else{
			for (i = 0; i < myfield.value.length; i++){
			// Check that current character is number.
				c = myfield.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s + " is not a valid number.")
					myfield.focus()
					return false;
				}
			}
			for (i = 0; i < myfield2.value.length; i++){
				// Check that current character is number.
				c = myfield2.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s2 + " is not a valid number.")
					myfield2.focus()
					return false;
				}
			}
			if (validateFirstPhoneNo(myfield, "First Phone No") &&
				validateSecondPhoneNo(myfield2 , "Second Phone No" )){
				return true;
			}else{
				return false;
			}
		}
	}
}	
	
}

function validateHpNo(myfield, s, myfield2, s2){
if (trim(myfield.value)==''){
    alert("The " + s + " is empty.")
    myfield.focus()
    return false
}else{
	if (trim(myfield.value)!=''){
		if (trim(myfield2.value)==''){
			alert("The " + s2 + " is empty.")
			myfield2.focus()
			return false
		}else{
			for (i = 0; i < myfield.value.length; i++){
			// Check that current character is number.
				c = myfield.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s + " is not a valid number.")
					myfield.focus()
					return false;
				}
			}
			for (i = 0; i < myfield2.value.length; i++){
				// Check that current character is number.
				c = myfield2.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s2 + " is not a valid number.")
					myfield2.focus()
					return false;
				}
			}
			if (validateFirstHpNo(myfield, "First Hand Phone No") &&
				validateSecondHpNo(myfield2 , "Second Hand Phone No" )){
				return true;
			}else{
				return false;
			}
		}
	}else if (trim(myfield2.value)!=''){
		if (trim(myfield.value)==''){
			alert("The " + s + " is empty.")
			myfield.focus()
			return false
		}else{
			for (i = 0; i < myfield.value.length; i++){
			// Check that current character is number.
				c = myfield.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s + " is not a valid number.")
					myfield.focus()
					return false;
				}
			}
			for (i = 0; i < myfield2.value.length; i++){
				// Check that current character is number.
				c = myfield2.value.charAt(i);
				if (((c < "0") || (c > "9"))) {
					alert("The " + s2 + " is not a valid number.")
					myfield2.focus()
					return false;
				}
			}
			if (validateFirstHpNo(myfield, "First Hand Phone No") &&
				validateSecondHpNo(myfield2 , "Second Hand Phone No" )){
				return true;
			}else{
				return false;
			}
		}
	}
	
}
}

function isInteger(myfield, s){

	if (trim(myfield.value)==''){
			myfield.focus()
			alert("The "+s+" is empty. Please enter a "+s)
			return false
	}else{
		for (i = 0; i < myfield.value.length; i++){
			// Check that current character is number.
			var c = myfield.value.charAt(i);
			if (((c < "0") || (c > "9"))) {
				alert("The " + s + " is not a valid number.")
			  	myfield.focus()
			  	return false;
			}
		}
		// All characters are numbers.
		return true;
	}

}
function validatePassword(myfield1, myfield2){
	if (trim(myfield1.value)==""){
		alert("Password field is empty. Please enter a password");
		myfield1.focus();
		return false;
	}else if(trim(myfield2.value)==""){
		alert("Confirm Password field is empty. Please enter a confirm password");
		myfield2.focus();
		return false;
	}else if (myfield1.value.length <= 7){
		alert("Password must have at least 8 characters");
			myfield1.focus();
			return false;
	}else if((trim(myfield1.value))!=(trim(myfield2.value))){
		alert("Passwords do not match each other");
		myfield1.focus();
		return false;
	}else{
		return true;
	}
}

function validateEmail(myfield, s){
	if (notNull(myfield.value)&& notBlank(myfield.value)){
		if (myfield.value.indexOf('@') == -1 || myfield.value.indexOf('.')==-1){
			myfield.focus()
			alert("Please enter a valid email.")
			return false	
 		}else{
			return true
		}
	}else {
		myfield.focus()
		alert("The " + s + emptyString + s)
		return false
	}
}
function notNull(str) {
	if (trim(str).length == 0 )
		return false
	else
		return true
}

function notBlank(str) {
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) != " ")
			return true
	}
	return false
}

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }

   if (inputString.length == 0) {
   		return inputString;
   }
   var retValue = inputString;

   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function isDigit (ch)
{
  return(ch>='0'&&ch<='9')
}
<!-- **************function to only allow digit otherwise it will return false******************-->
function isDigitonly(str)
{
  var i;
  for(i=0;i<str.length;i++)
  {
    if(!isDigit(str.charAt(i)))return false;
  }
 return true;
}

<!--*****************function to check the content is alphabet or not********************** -->
function isAlphabet(ch)
{
return ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'));
}

//function to only allow alphabet otherwise it will return false
function charonly(str)
{
  var i;
  for(i=0;i<str.length;i++)
  {
    if(!isAlphabet (str.charAt(i)))
    return false;
  }
 return true;
}

function validateString(myfield, s) {
	if (notNull(myfield.value)&& notBlank(myfield.value))
		return true
	else {
		myfield.focus()
		alert("The " + s + emptyString + s + ".")
		return false
	}
}

function validateCombo(myfield, s) {
	if (notNull(myfield.value)&& notBlank(myfield.value))
		return true
	else {
		myfield.focus()
		alert("The " + s + emptyCombo + s + ".")
		return false
	}
}

function brandOnSelect(){
	var brand;
	brand = document.form1.productBrand.value;
	if (brand != ""){ 
		document.location.href = "productBrand.asp?brandId=" + brand;
	}
}

function priceOnChange(){
	var price;
	price = document.form1.productPrice.value;
	if (price != ""){ 
		document.location.href = "productPrice.asp?price=" + price;
	}
}

function sizeOnChange(){
	var size;
	size = document.form1.productSize.value;
	if (size != ""){ 
		document.location.href = "productSize.asp?size=" + size;
	}
}

function specialLink(s1, s2){
	document.location.href = "productCategory.asp?parentCategory="+ s1 +"&category=" + s2;
}

function validateSearch(){
	var keyword = document.form1.keyword;
	//alert('asdf');
	if ( validateString(keyword, "Keyword")){
		keyword = escape(keyword.value);
		document.location.href = "productSearchResult.asp?keyword=" + keyword;
	}
	return false;
}

function addFavoriteLink(){
if(window.sidebar){
	 window.sidebar.addPanel(document.title,location.href,'');
 }else if(window.external){
	 window.external.AddFavorite(location.href,document.title);
 }else if(window.opera&&window.print){ 
		 //return true; 
 }
}

//Start Image Rollover Functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// End Image Rollover Functions

// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com
// Original:  Matthew (battlebots102001@yahoo.com)
// Web Site:  http://geocities.com/battlebots102001/javascript_gizmos/index.htm

// Start Scrolling Functions
function scroll(message_loop)
{
var messages = new Array();
messages[0] = "Welcome to Sonali.com.my!";
messages[1] = "Sonali is the \"Symbol of Style\"";
messages[2] = "We Believe You Deserve The Best With Us!";
messages[3] = "We Provide Professional Design in Sarees, Salwar Kameez, Tops, and a lot more.";
messages[4] = "Therefore, Sonali Is Always Your Best Choice!";

if(message_loop >= messages.length)
{
message_loop = 0;
}
//var old_value = window.document.form1.banner.value;
var old_value = document.getElementById("banner").innerHTML;
var new_value;
var random = Math.floor(Math.random() * messages[message_loop].length);
var change_letter = messages[message_loop].charAt(random);
if(old_value == messages[message_loop])
{
message_loop++;
setTimeout("scroll("+message_loop+")",4000);
return;
}
if(change_letter == old_value.charAt(random))
{
scroll(message_loop);
return;
}
var first_part = old_value.substring(0,random);
random++;
var last_part = old_value.substring(random,messages[message_loop].length);
var new_value = first_part + change_letter + last_part;
//window.document.form1.banner.value = new_value;
document.getElementById("banner").innerHTML = new_value;
setTimeout("scroll("+message_loop+")",200);
}