
/*var win = null;
function myNewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+false+',resizable'
	win = window.open(mypage,myname,settings)
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+false+',resizable'
	win = window.open(mypage,myname,settings)
}*/


function close_win(isrefresh){
	if(isrefresh == 1){
		opener.location.reload(true);
	}
	self.close();
}

function textAreaCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function emailAddresscheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ 
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    
		    return false
		 }

 		 return true					
	}
	


function redirect(url,is_canel){
	var doit = true;
	if(is_canel){
		doit =	confirm("Are you sure you want to cancel ?");
	}
	if(doit){
		window.location = url;
	}
}

function checkMultipleImage(form,fileString) { 
	var is_err = false; 
	
	//check if there's only of FILE input - validate IT!
	if(form.elements[fileString+'[]'].value == ''){
		is_err = false;
	}else{
		if(form.elements[fileString+'[]'].length){
			for (i=0; i<form.elements[fileString+'[]'].length; i++){ 
					if(form.elements[fileString+'[]'][i].value.trim() != '') {
					is_err = true;
				} 
			} 
		}else{
			is_err = true;	
		}
	}
	return is_err;
} 

function clearField(field){
	field.value ='';
}

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
	  if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
	}
}

function NumChecked(form,checkbox) {
	len = form.elements.length;

	num = 0;
	for(var i=0; i<len; ++i) {
		if(form.elements[i].name == checkbox && form.elements[i].checked) ++num;
	}
	return num;
}

function Delete(form,checkbox) {	
	num=NumChecked(form,checkbox);
	if(num==0) {
		alert("No selection to delete.");
		return false;
	}
	if(confirm("Are you sure you want to delete selected items ?")) {
		return true;
	}else{
		return false;	
	}
}


function ValidatePostSelection(formName,checkbox,obj) {	
	var form = getDIV(formName);
	num=NumChecked(form,checkbox);
	if(num==0) {
		alert("No selection to take action");
		return false;
	}
	if(confirm("Are you sure you want to perform action on selectem items?")) {
		form.actiontype.value = obj.value;
		form.submit();
		return true;
	}else{
		return false;	
	}
}


function calculateCurrentString(table){
	var rows = table.tBodies[0].rows;
    var postStr = "";
    for (var i=0; i<rows.length; i++) {
        postStr += rows[i].id+":";
    }
	return postStr;
}

function checkUncheck(currentRow,checkall){
	var docheck = checkall.value;
	if(docheck == 1) checkall.value = 0;
	else checkall.value = 1;
	for(var i=1;i<5;i++){
		var elem = document.getElementById(currentRow+"_"+i);
		if(docheck == 1){
			elem.checked = true;
		}else{
			elem.checked = false;	
		}
	}
}

function validateImg(fileName){	
	if (fileName.trim() == "") return false;
	var stringArray = fileName.split ('.');
	var len = stringArray.length-1;
	var fileExtension = stringArray[len].toLowerCase();  
      switch (fileExtension) {
        case 'jpeg': 
        case 'jpg':
        case 'gif':
        case 'png':
           break;
        default:
          return false;
      }
	  return true;
}

function validateAudio(fileName){	
	if (fileName.trim() == "") return false;
	var stringArray = fileName.split ('.');
	var len = stringArray.length-1;
	var fileExtension = stringArray[len].toLowerCase();  
      switch (fileExtension) {
        case 'mp3': 
           break;
        default:
          return false;
      }
	  return true;
}

function errhideDiv(divid){
	document.getElementById(divid+"err").style.display = "none";
}


function errshowDiv(divid){
	document.getElementById(divid+"err").style.display = "";
}

function setDIVvalue(divid,valueString){
	document.getElementById(divid).innerHTML = valueString;
}

function setElementvalue(divid,valueString){
	document.getElementById(divid).value = valueString;
}


function getDIV(divid){
	return document.getElementById(divid);
}


function getDIVvalue(divid){
	return document.getElementById(divid).value;
}

function isValidDiv(divid){
	if(document.getElementById(divid)) return true;
	else return false;
}
function showDIV(divid){
	document.getElementById(divid).style.display="";
}

function hideDIV(divid){
	document.getElementById(divid).style.display="none";
}

function ValidateTimeString(string){
	//var myRegExp = new RegExp("^[0-9]+:[0-9]+ [aApP]+[mM]+$");
	var myRegExp = new RegExp("^[0-9]+:[0-9]+$");
	
	var myarray  = string.split(":");
	var hour  = myarray[0];
	var mins  = myarray[1];
	
	if(hour == 24){
		if(mins > 0 ){
			return false;
		}
	}
	
	if(myRegExp.exec(string) == null || isNaN(hour) || isNaN(mins) || hour.length >= 3 || mins.length >= 3 
	|| hour > 24 || hour < 0 || mins > 59 || mins < 0 ){
		return false;
	}else{
		return true;
	}
}

function ValidateLink(theurl){
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl)){
         return true;
     }else{
		 return false;
	 }
}
function ValidateURL(url) {
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(url)) {
        return false;
    }else{
		return true;
	}
} 