﻿function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
var p_id="";
function getstates(target) {


    http.open('get', 'ajax_response.aspx?country_id='+target.value);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function nextimage(image_id,id,profile_id,imagecount) {

    p_id=profile_id;
    http.open('get', 'ajax_response.aspx?image_id='+image_id +'&id='+id+'&profile_id='+profile_id+'&imagecount='+imagecount);
    http.onreadystatechange = handleResponseImage;
    http.send(null);
}

function handleResponseImage() {
    if(http.readyState == 4){
        var response = http.responseText;
            document.getElementById(p_id).innerHTML = response;
         
    }
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
            document.getElementById("astates").innerHTML = response;
         
    }
}
		function IsValidString(checkStr)
			{
				var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
				var allValid = true;
				if (checkStr.length<1)
				allValid=false;
				for (i=0;i<checkStr.length;i++)
				{
					ch=checkStr.charAt(i);
					for(j=0;j<checkOK.length;j++)
					if(ch==checkOK.charAt(j))
						break;
					if(j==checkOK.length)
					{
					allValid = false;
					break;
					}
				}
				return allValid;
			}
			function isDate(datestr, Dilimeter)
			{
				var lthdatestr
				if (datestr != '')
					lthdatestr= datestr.length ;
				else
					lthdatestr=0;

				if (Dilimeter=='' || Dilimeter==null)
					Dilimeter = '-';

				var tmpy='';
				var tmpm='';
				var tmpd='';
				//var datestr;
				var status;
				status=0;
				if ( lthdatestr== 0)
					return true;
				for (i=0;i<lthdatestr;i++) 
				{
					if (datestr.charAt(i)== Dilimeter) {status++;}
					if (status>2) { return false; }
					if ((status==0) && (datestr.charAt(i)!=Dilimeter)) { tmpy=tmpy+datestr.charAt(i) }
					if ((status==1) && (datestr.charAt(i)!=Dilimeter)) { tmpm=tmpm+datestr.charAt(i) }
					if ((status==2) && (datestr.charAt(i)!=Dilimeter)) { tmpd=tmpd+datestr.charAt(i) }
				}
				year=new String (tmpy);
				month=new String (tmpm);
				day=new String (tmpd)
				if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2)) { return false; }
				if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) ) { return false; }
				if (!((year % 4)==0) && (month==2) && (day==29)) { return false; }
				if ((month<=7) && ((month % 2)==0) && (day>=31)) { return false; }
				if ((month>=8) && ((month % 2)==1) && (day>=31)) { return false; }
				if ((month==2) && (day==30)) { return false; }
				return true;
			}
			function Jtrim(str)
			{
				var i = 0;
				var len = str.length;
				var j =0;
				
				if ( str == "" ) return( str );
				if (str.length == 0) return( str );
				if(str==null) return( "");
				
				j = len -1;
				var flagbegin = true;
				var flagend = true;

				while (flagbegin == true && i< len)
				{
					if ( str.charAt(i) == " " )
					{
						i=i+1;
						flagbegin=true;
					}
					else
					{
						flagbegin=false;
					}
				}

				while  (flagend== true && j>=0)
				{
					if (str.charAt(j)==" ")
					{
						j=j-1;
						flagend=true;
					}
					else
					{
						flagend=false;
					}
				}

				if ( i > j ) return ("");

				trimstr = str.substring(i,j+1);
				return trimstr;
			}

function DrawImage(ImgD,iwidth,iheight){

	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){ 
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}
	}
}

